package cn.jasonone.controller;

import cn.jasonone.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 导出Excel
 * @author xujie
 * @version 1.0.0
 */
@Controller
@RequestMapping("/export/excel")
public class ExcelController {
    private List<Student> students = new ArrayList<>();

    @GetMapping
    public String export(Model model) {
        model.addAttribute("students", students);
        return "Student";
    }

    /**
     * 保存数据请求
     * @param students
     * @return
     */
    @PutMapping
    @ResponseBody
    public Map<String, Object> saveData(@RequestBody Student[] students) {
        this.students.addAll(Arrays.asList(students));
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        return result;
    }
}
